/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.sucresale.facade;

import com.sucresale.entities.Users;
import com.sun.tools.example.debug.gui.ContextManager;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Users
 */
@Stateless
public class UserSessionBean implements UserSessionBeanLocal {


    @PersistenceContext(unitName="SucreSale-ejbPU")
    private EntityManager em;

    public boolean checkCredentials(String username, String password) {

        try{

        String _tempPassword = em.createNamedQuery("User.getPassword").setParameter("username", username).getSingleResult().toString();

        if(_tempPassword.equals(password)){

            return true;

        }

        }catch(NoResultException e){

            return false;

        }

        return false;
        
    }

    public Users getAllInfoFromUser(String username) {

        Users _tempUser = (Users) em.createNamedQuery("User.getAllInformation").setParameter("username", username).getSingleResult();

        return _tempUser;
    }
    



 
}
